package cn.shengongying.api.controller;

import cn.shengongying.anon.User;
import cn.shengongying.api.dto.BossInDTO;
import cn.shengongying.api.vo.BossInfoVo;
import cn.shengongying.bean.BaseUser;
import cn.shengongying.bean.ResponseResult;
import cn.shengongying.model.Customer;
import cn.shengongying.service.ICustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * author: RXK
 * date: 2022/1/5 星期三
 * desc:
 */
@RestController
@Api(tags = "雇主(基本信息、更新信息)")
@RequestMapping("/boss")
public class BossController {


    private final ICustomerService customerService;

    public BossController(ICustomerService customerService) {
        this.customerService = customerService;
    }

    @PostMapping("/info")
    @ApiOperation(value = "基本信息", response = BossInfoVo.class)
    public ResponseResult<BossInfoVo> info(@ApiIgnore @User BaseUser baseUser) {
        Customer customer = customerService.getById(baseUser.getId());
        BossInfoVo vo = BossInfoVo.build(customer);
        return ResponseResult.success(vo);
    }


    @ApiOperation(value = "更新基本信息")
    @PostMapping("/info/update")
    public ResponseResult<String> update(@ApiIgnore @User BaseUser baseUser, @RequestBody BossInDTO inDTO) {
        Customer customer = inDTO.build(baseUser.getId());
        if (null != customer) {
            customerService.updateById(customer);
        }
        return ResponseResult.success();
    }

}
